//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.common.utils.jkalman;


import com.ruoyi.common.utils.jkalman.jama.Matrix;
import com.ruoyi.common.utils.jkalman.jkalman.JKalman;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class JKalmanUtils {
    private static final String TAG = "JKalmanUtils";
    private JKalman mJkalman;
    private Matrix mMeasurementValue;
    private Matrix s;
    private Matrix c;

    protected Logger log = LoggerFactory.getLogger(JKalmanUtils.class);

    public void init() {
        try {
            this.mJkalman = new JKalman(2, 1);
            this.mMeasurementValue = new Matrix(1, 1);
            this.s = new Matrix(2, 1);
            this.c = new Matrix(2, 1);
            double[][] tr = new double[][]{{1.0, 0.0}, {0.0, 1.0}};
            this.mJkalman.setTransition_matrix(new Matrix(tr));
            this.mJkalman.setError_cov_post(this.mJkalman.getError_cov_post().identity());
        } catch (Exception var2) {
            log.info(var2.getMessage());
        }

    }

    public float correctVel(float value) {
        if (this.mJkalman == null || this.mMeasurementValue == null) {
            this.init();
        }

        this.mMeasurementValue.set(0, 0, (double)value);
        this.s = this.mJkalman.Predict();
        this.c = this.mJkalman.Correct(this.mMeasurementValue);
        return (float)this.c.get(0, 0);
    }

    public List<Float> correctList(List<Float> valList) {
        if (this.mJkalman == null || this.mMeasurementValue == null) {
            this.init();
        }

        List<Float> valCacheList = new ArrayList(valList);
        List<Float> floats = new ArrayList();
        Iterator var4 = valCacheList.iterator();

        while(var4.hasNext()) {
            Float value = (Float)var4.next();
            if (value != null) {
                this.mMeasurementValue.set(0, 0, (double)value);
                this.s = this.mJkalman.Predict();
                this.c = this.mJkalman.Correct(this.mMeasurementValue);
                floats.add((float)this.c.get(0, 0));
            }
        }

        return floats;
    }

    public void release() {
        this.mJkalman = null;
        this.mMeasurementValue = null;
        this.s = null;
        this.c = null;
    }

    public JKalmanUtils() {
    }

    public static JKalmanUtils getInstance() {
        return JKalmanUtils.SingletonInstance.INSTANCE;
    }

    private static class SingletonInstance {
        private static final JKalmanUtils INSTANCE = new JKalmanUtils();

        private SingletonInstance() {
        }
    }
}
